﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_GuestBook.cs
* 创建标识：曾乃强 15158756652 2011-03-17 11:03:01
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_GuestBook*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_GuestBook
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_GuestBook obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "GuestBook ([GBAuthor],[GBTitle],[GBContent],[AddTime],[IsShow],[IsDelete])");
            sql.Append("values(@GBAuthor,@GBTitle,@GBContent,@AddTime,@IsShow,@IsDelete)");
            
            SqlParameter[] pra = {
                            new SqlParameter("@GBAuthor",obj.GBAuthor),
							new SqlParameter("@GBTitle",obj.GBTitle),
							new SqlParameter("@GBContent",obj.GBContent),
							new SqlParameter("@AddTime",obj.AddTime),
							new SqlParameter("@IsShow",obj.IsShow),
							new SqlParameter("@IsDelete",obj.IsDelete)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public int Update(Model.CNVP_GuestBook obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "GuestBook set [GBAuthor] = @GBAuthor,[GBTitle] = @GBTitle,[GBContent] = @GBContent,[AddTime] = @AddTime,[IsShow] = @IsShow,[IsDelete] = @IsDelete where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@GBAuthor",obj.GBAuthor),
							new SqlParameter("@GBTitle",obj.GBTitle),
							new SqlParameter("@GBContent",obj.GBContent),
							new SqlParameter("@AddTime",obj.AddTime),
							new SqlParameter("@IsShow",obj.IsShow),
							new SqlParameter("@IsDelete",obj.IsDelete)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_GuestBook obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "GuestBook where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }


        public Model.CNVP_GuestBook LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [GBAuthor],[GBTitle],[GBContent],[AddTime],[IsShow],[IsDelete] from " + Prefix + "GuestBook");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_GuestBook cnvp_guestbook = new Model.CNVP_GuestBook();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_guestbook.GBAuthor = dr["GBAuthor"] is DBNull ? String.Empty : (string)dr["GBAuthor"];
                cnvp_guestbook.GBTitle = dr["GBTitle"] is DBNull ? String.Empty : (string)dr["GBTitle"];
                cnvp_guestbook.GBContent = dr["GBContent"] is DBNull ? String.Empty : (string)dr["GBContent"];
                cnvp_guestbook.AddTime = dr["AddTime"] is DBNull ? DateTime.Now : (DateTime)dr["AddTime"];
                cnvp_guestbook.IsShow = dr["IsShow"] is DBNull ? (byte)0 : (byte)dr["IsShow"];
                cnvp_guestbook.IsDelete = dr["IsDelete"] is DBNull ? (byte)0 : (byte)dr["IsDelete"];
            }
             return cnvp_guestbook;
        }

        #endregion
    }
}

